import { Service } from 'egg'

function toInt(str) {
  if (typeof str === 'number')
    return str
  if (!str)
    return str
  return parseInt(str, 10) || 0
}

export default class MenuService extends Service {
  async list() {
    const { ctx } = this

    const query = {
      limit: toInt(ctx.query.limit),
      offset: toInt(ctx.query.offset),
    }
    const menuList = await ctx.model.Menu.findAll(query)
    return menuList
  }
}